<template>
  <a-config-provider :locale="locale">
    <router-view></router-view>
  </a-config-provider>
</template>

<script setup lang="ts">
import zhCN from 'ant-design-vue/es/locale/zh_CN';
import enUS from 'ant-design-vue/es/locale/en_US';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import { onMounted, computed } from 'vue';
import { useI18n } from 'vue-i18n';
import { getBrowserLang } from '@/utils';
import type { LanguageType } from './store/interface';
import { useGlobalStore } from '@/store/modules/global';
dayjs.locale('zh-cn');

// const locale = zhCN;
const globalStore = useGlobalStore();
// init language
const i18n = useI18n();
onMounted(() => {
  const language = globalStore.language ?? getBrowserLang();
  i18n.locale.value = language;
  globalStore.changeGlobal(language as LanguageType);
});

// element language
const locale = computed(() => {
  if (globalStore.language == 'zh') return zhCN;
  if (globalStore.language == 'en') return enUS;
  return getBrowserLang() == 'zh' ? zhCN : enUS;
});
</script>

<style lang="scss" scoped></style>
